#pragma once

#include <QVector>
#include <QPointF>
#include <QColor>
#include <QRectF>
#include <QString>

namespace kernel {

struct StationDisplayInfo {
    QPointF position;
    QString name;
    QString className;      // "LocationMark", "ActionPoint"
    QString stationType;    // "Normal", "Charge", "Fork", "Park"
    double direction{0.0};  // Direction in radians
    bool isSelected{false};
    int vertex{0};          // Algorithm-defined vertex number

    StationDisplayInfo() = default;
    StationDisplayInfo(const QPointF& pos, const QString& n, const QString& cls = "LocationMark",
                      const QString& type = "Normal", double dir = 0.0)
        : position(pos), name(n), className(cls), stationType(type), direction(dir) {}
};

struct PathDisplayInfo {
    QVector<QPointF> points;
    QColor color{QColor("#409F41")};
    QString pathType;       // "bezier", "straight", "arc"
    QString name;

    PathDisplayInfo() = default;
    PathDisplayInfo(const QVector<QPointF>& pts, const QString& type = "straight",
                   const QColor& col = QColor("#409F41"))
        : points(pts), pathType(type), color(col) {}
};

struct AreaDisplayInfo {
    QVector<QPointF> points;
    QString name;
    QString areaType;       // "work", "block", "charge", "park", "normal"
    QColor fillColor{QColor("#C9F970")};
    QColor borderColor{QColor("#409F41")};
    double opacity{0.3};    // 透明度 (0.0-1.0)
    bool showName{true};    // 是否显示名称

    AreaDisplayInfo() = default;
    AreaDisplayInfo(const QVector<QPointF>& pts, const QString& n = "", 
                   const QString& type = "normal", const QColor& fill = QColor("#C9F970"),
                   const QColor& border = QColor("#409F41"), double op = 0.3)
        : points(pts), name(n), areaType(type), fillColor(fill), borderColor(border), opacity(op) {}
};

struct MapDisplayDto {
    // Map bounds and metadata
    QString mapName;
    QRectF bounds;
    double resolution{1.0};

    // Enhanced station information
    QVector<StationDisplayInfo> stations;

    // Enhanced path information
    QVector<PathDisplayInfo> paths;

    // Enhanced area information
    QVector<AreaDisplayInfo> areas;
    QVector<QPointF> normalPoints;
    
    // Legacy area information (deprecated)
    QVector<QVector<QPointF>> legacyAreas;
    QVector<QVector<QPointF>> blockAreas;

    // Legacy compatibility (deprecated - use enhanced versions above)
    QVector<QPointF> stationPoints;
    QVector<QString> stationNames;
    QVector<QVector<QPointF>> bezierCurves;
    QVector<QVector<QPointF>> straightPaths;
    QVector<QVector<QPointF>> arcPaths;
    QVector<QColor> pathColors;
    QVector<double> pathWidths;

    MapDisplayDto() = default;

    bool isEmpty() const {
        return mapName.isEmpty() || (stations.isEmpty() && stationPoints.isEmpty());
    }

    void clear() {
        mapName.clear();
        bounds = QRectF();
        resolution = 1.0;
        stations.clear();
        paths.clear();
        areas.clear();
        normalPoints.clear();

        // Clear legacy fields
        legacyAreas.clear();
        blockAreas.clear();
        stationPoints.clear();
        stationNames.clear();
        bezierCurves.clear();
        straightPaths.clear();
        arcPaths.clear();
        pathColors.clear();
        pathWidths.clear();
    }

    // Helper method to populate legacy fields from enhanced data
    void syncLegacyFields() {
        stationPoints.clear();
        stationNames.clear();

        for (const auto& station : stations) {
            stationPoints.append(station.position);
            stationNames.append(station.name);
        }

        bezierCurves.clear();
        straightPaths.clear();
        arcPaths.clear();
        pathColors.clear();

        for (const auto& path : paths) {
            if (path.pathType == "bezier") {
                bezierCurves.append(path.points);
            } else if (path.pathType == "straight") {
                straightPaths.append(path.points);
            } else if (path.pathType == "arc") {
                arcPaths.append(path.points);
            }
            pathColors.append(path.color);
        }
    }
};

} // namespace kernel